#include "stdafx.h"


struct shape_util2
{
    sf::ConvexShape Polygon;
    //sf::Shape Polygon;
    sf::RenderWindow * window;

    map<string, sf::Sprite> sprites;
    map<string, sf::Texture> textures;

    void init()
    {
        window = new sf::RenderWindow (sf::VideoMode(800, 600), "procedural shape utility");

        window->setMouseCursorVisible(false);


        textures["cursor"] = sf::Texture();
        textures["bg"] = sf::Texture();
        sprites["cursor"] = sf::Sprite();
        sprites["bg"] = sf::Sprite();

        textures["bg"].loadFromFile("grid.png");
        textures["cursor"].loadFromFile("cursor.png");
        sprites["bg"].setTexture(textures["bg"]);
        sprites["cursor"].setTexture(textures["cursor"]);
        Polygon.setFillColor(sf::Color(0,200,0, 255));


        Polygon.setPointCount(6);
        Vector2f points[6] = 
        {
            Vector2f(10,10),
            Vector2f(50,5),
            Vector2f(90,20),
            Vector2f(80,50),
            Vector2f(60,60),
            Vector2f(30,50)
        };
        FOR(6)
        {
            Polygon.setPoint(i, points[i]);
        }
        size_t u = Polygon.getPointCount();
        cout << "point begin" << endl;
        FOR(u)
            cout << "    point " << i << ": " <<
                Polygon.getPoint(i).x << " " << Polygon.getPoint(i).y << endl;
        cout << "point end" << endl;

    }
    ~shape_util2() { delete window; }
    void handle_loop()
    {
        while (window->isOpen())
        {
            sf::Event event;
            while (window->pollEvent(event))
            {
                if (event.type == sf::Event::Closed)// || event.type==sf::Event::KeyPressed)
                    window->close();
                if(event.type == sf::Event::KeyPressed)// || event.type == sf::Event::KeyReleased)
                    switch(event.key.code)
                    {
                    case Keyboard::Escape:
                        window->close();
                        break;
                    }
                if(event.type == sf::Event::MouseButtonPressed)
                {
                    Polygon.setPoint(3, Vector2f(90,60));
                }
                if(event.type == sf::Event::MouseButtonReleased)
                {
                    Polygon.setPoint(3, Vector2f(80,50));
                }

                            

                
                    
                window->clear();
                //window->draw(sprites["bg"]);

                window->draw(Polygon);


                //window->draw(sprites["cursor"]);
                window->display();

            }
        }
    }

};